#include "stack.h"

stackC *StackCCreater()
{
	stackC * p = (stackC *)malloc(sizeof(stackC));
	if(p == NULL)				// fail creater
		return 0;
	p->top = p->buttom = 0;	// success creater and init the top equal the end
	return p;
}

int IsCEmpty(stackC * p)
{
	return (p->top == p->buttom);
}

int StackCTop(stackC * p)
{
	return p->data[p->top];
}


void StackPushChar(stackC * p, char str)
{
	if(p->top == 100)	return;			// the stack is full
	p->data[p->top] = str;	// push str int the top of stack
	p->top++;								// top add
}

char StackCPop(stackC * p)
{
	if(IsCEmpty(p) == 1)	// the stack is empty
		return 0;
	return p->data[--p->top];	//	else return the top element of the stack
}

void StackCCheck(stackC *p)
{
	int temp = p->top;
	while(temp != p->buttom)
	{
		printf("%c",p->data[--temp]);
	}
}

// num stack achive
stackN *StackNCreater()
{
	stackN * p = (stackN *)malloc(sizeof(stackN));
	if(p == NULL)				// fail creater
		return 0;
	p->top = p->buttom = 0;	// success creater and init the top equal the end
	return p;
}

int IsNEmpty(stackN * p)
{
	return (p->top == p->buttom);
}

int StackNTop(stackN * p)
{
	return p->data[p->top];
}

void StackPushNum(stackN * p, int num)
{
	if(p->top == 100)	return;			// the stack is full
	p->data[p->top] = num;	// push str int the top of stack
	p->top++;								// top add
}

char StackNPop(stackN * p)
{
	if(IsNEmpty(p) == 1)	// the stack is empty
		return 0;
	return p->data[--p->top];	//	else return the top element of the stack
}
void StackNCheck(stackN *p)
{
	int temp = p->top;
	while(temp != p->buttom)
	{
		printf("%c",p->data[--temp]);
	}
}

void freeStack(stackC * c, stackN * n)
{
	free(c);
	free(n);
}
